package com.hmsm.sys.daoImpl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import com.hmsm.server.base.BaseDao;
import com.hmsm.sys.dao.SysConfigDao;
import com.hmsm.sys.po.SysConfig;

@Repository
public class SysConfigDaoImpl extends BaseDao<SysConfig, Integer> implements SysConfigDao {

	@Override
	public List<SysConfig> getByName(String name) {
		String hql = "FROM SysConfig o WHERE o.name like '"+name+"'" ;
		return queryByHql(hql) ;
	}

	/**
	 *  @描述:更新name的值
	 *  @方法名称:updateSysConfigParam
	 *  @作者:fengtao
	 *  @创建日期:2014-5-30 上午11:41:35 
	 *  @param parameter
	 *  @return
	 **/
	@Override
	public void updateSysConfigParam(final String name, final String parameter){
		getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				String hql = "update SysConfig set VALUE = '" + parameter + "' where name = '" + name + "'";
				return session.createQuery(hql).executeUpdate();
			}
		});
	}

}
